package graphNew;

import org.jgrapht.graph.DefaultWeightedEdge;

public class FlowingEdge extends DefaultWeightedEdge {
	private double capacity;
	private double flow;
	
	
	/**
	 * CONSTRUCTOR
	 */
	public FlowingEdge() {
		capacity=super.getWeight();
		flow=0;
	}

	
	/**
	 * GETTER
	 * @return what flows in the edge
	 */
	public double getFlow() {
		return flow;
	}


	/**
	 * sets f more in the flow
	 * @param f
	 * @throws Exception if flow is out of bounds (0-capacity)
	 */
	public void setFlow(double f) throws Exception {
		this.flow += f;
		if (this.flow<0 || this.flow>capacity)
			throw new Exception ("flow out of chart"+toString());
	}


	/**
	 * GETTER 
	 * @return
	 */
	public double getCapacity() {
		return capacity;
	}
	
	/**
	 * SETTER
	 * @param cap
	 */
	public void setCapacity(double cap){
		capacity=cap;
	}
	
	public String toString(){
		return super.toString()+" "+flow+"/"+capacity;
	}


	/**
	 * reset flow
	 */
	public void reset() {
		this.flow=0;
	}

}
